#include <windows.h>
#include <stdlib.h>

char buf[10240];
void Print(const char *str, ...)
{

    int i = 0, k = 0;
    va_list var;
    unsigned char c;
    unsigned char c1;
    va_start(var, str);
    c = *(str + k);
    while (c != '\0')
    {
        c1 = *(str + k + 1);
        if (c == '%')
        {
            if (c1 == 'd')
            {
                int t = va_arg(var, int);
                char b[10];
                itoa(t, (char *)b, 10);
                memcpy((void *)(buf + i), b, strlen((char *)b));
                i += strlen((char *)b);
                k += 2;
            }
            else
            {
                buf[i++] = c;
                k++;
            }
        }
        else
        {
            buf[i++] = c;
            k++;
        }
        c = *(str + k);
    }
    va_end(var);
    buf[i] = 0;
    OutputDebugString((char *)buf);
}

int main()
{
    int a = 100;
    Print("num is %d", a);
}
